package com.gitee.zhanyao.security.service.impl;

import com.gitee.zhanyao.api.security.model.OAuth2User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

/**
 * @author zhanyao
 */
@Service("userDetailsService")
public class UserDetailServiceImpl implements UserDetailsService {

    private final PasswordEncoder passwordEncoder;

    @Autowired
    public UserDetailServiceImpl(PasswordEncoder passwordEncoder) {
        this.passwordEncoder = passwordEncoder;
    }

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        /*
        if (null == null) {
            throw new UsernameNotFoundException(username + " 该用户不可用");
        }
        */
        return new OAuth2User("zhanyao", passwordEncoder.encode("123456"),
                AuthorityUtils.commaSeparatedStringToAuthorityList(""), "zhanyao@qq.com");
    }

}
